/*
 * =====================================================================================
 *
 *       Filename:  Strategy.cpp
 *
 *    Description:  
 *
 *        Version:  1.0
 *        Created:  2015年01月21日 17时28分26秒
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  LiuYi (), swliuyi@gmail.com
 *   Organization:  
 *
 * =====================================================================================
 */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <limits.h>
#include <iostream>

using namespace std;

class CashSuper
{
    public:
        double virtual AcceptCash(double money) = 0;
        virtual ~CashSuper(){}
};

class CashNormal: public CashSuper
{
    public:
        virtual ~CashNormal(){}
        double AcceptCash(double money)
        {
            return money;
        }
};

class CashRebate : public CashSuper
{
    private:
        double MoneyRebate;
    public:
        CashRebate(double r = 1):MoneyRebate(r) { }
        virtual ~CashRebate(){}
        double AcceptCash(double money)
        {
            return money * MoneyRebate;
        }
};

class CashReturn : public CashSuper
{
    private:
        double MoneyCondition;
        double MoneyReturn;
    public:
        CashReturn(double mc, double mr):MoneyCondition(mc), MoneyReturn(mr){}
        virtual ~CashReturn(){}
        double AcceptCash(double money)
        {
            double result = money;
            if(money >= MoneyCondition)
            {
                result = money - int(money / MoneyCondition) * MoneyReturn;
            }
            return result;
        }
};

class CashContext
{
    private:
        CashSuper *cs;
    public:
        ~CashContext()
        {
            delete cs;
        }
        CashContext(string type)
        {
            if( type == "正常收费" )
            {
                cs = new CashNormal();
            }
            else if(type == "满300返100")
            {
                cs = new CashReturn(300, 100);
            }
            else if( type == "打8折" )
            {
                cs = new CashRebate(0.8);
            }
        }
        double GetResult(double money)
        {
            return cs->AcceptCash(money);
        }
};

int main(int argc, char *argv[])
{
    double total = 0.0;

    CashContext *csuper = new CashContext("正常收费");
    total += csuper->GetResult(100*5);
    delete csuper;

    csuper = new CashContext("打8折");
    total += csuper->GetResult(100*5);
    delete csuper;

    csuper = new CashContext("满300返100");
    total += csuper->GetResult(100*5);
    delete csuper;

    cout<<total<<endl;
}
